<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.ncp.model.biz.comment.CommentCl"%>
<%@page import="com.ncp.model.entity.comment.ProductComment"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%
int id=1;
int nowPage=1;
int showPages=2;
int size=2;
String p=request.getParameter("page");
if(p!=null&&!p.equals("")){
	nowPage=Integer.parseInt(p);
}
if((String)request.getParameter("id")!=null){
	id=Integer.parseInt((String)request.getParameter("id"));
}
CommentCl cc=new CommentCl();
int PageCount=cc.getCount(id);
ArrayList<ProductComment> list=cc.getCommentInfo(id,nowPage);
ProductComment pc=null;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>评论展示</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <a href="ManagerShowBasicServlet?type=del&PageNow=1">return</a>
    <%
    for(int i=0;i<list.size();i++){
    	
    	 pc=list.get(i);
    	 if(!pc.getComment().equals("")){
    		 if(pc.getIsDisplayUserName()==1){
        		 %>
        		 	<div>用户<%=cc.getUsername(pc.getUserID())%>给出<%for(int j=0;j<5;j++) {
    	    		if(j<pc.getScore()){
        				 %>
         	    		<img src="images/absulote/icon_star_2.gif">
         	    		<%
        			 }else{
        				 %>
          	    		<img src="images/absulote/icon_star_1.gif">
          	    		<%
        			 }
    	    	}
    	    	%>的评分<%=pc.getCommentTime() %>
    	    	
    	    	<a href="AdminCommentServlet?cid=<%=pc.getCommentID() %>&flag=delete">delete</a>\<a href="pages/comment/admin/update.jsp?cid=<%=pc.getCommentID() %>">update</a></div>
        		 <%
        	 }else{
        		 %>
        		 <div>匿名用户给出<%for(int j=0;j<5;j++) {
        			 if(j<pc.getScore()){
        				 %>
         	    		<img src="images/absulote/icon_star_2.gif">
         	    		<%
        			 }else{
        				 %>
          	    		<img src="images/absulote/icon_star_1.gif">
          	    		<%
        			 }
    	    		
    	    	}
    	    	%>的评分<%=pc.getCommentTime() %><a href="AdminCommentServlet?cid=<%=pc.getCommentID() %>&flag=delete">delete</a>\<a href="pages/comment/admin/update.jsp?cid=<%=pc.getCommentID() %>">update</a></div>
        		 <%
        	 }
        	%>
        
        	<div><%=pc.getComment() %></div>
        	<%
    	 }
    }
    %>
	
	<div id="page">
					<ul>
					
					<% 
					if(nowPage>1){
						%><a href="pages/comment/admin/showComment.jsp?page=<%=nowPage-1 %>&id=<%=id %>" class="page">上一页</a><%
					}
					
					
					
						if(PageCount>=showPages){
							if(nowPage-size<=0){
								for(int i=1;i<=showPages;i++){
									%>
									
									<a href="pages/comment/admin/showComment.jsp?page=<%=i %>&id=<%=id %>" class="num" ><%=i %></a>
									<%
								}
								%>...<%
							}else if(nowPage+size<PageCount){
								for(int i=nowPage-size;i<=nowPage+size;i++){
									%>
									
									<a href="pages/comment/admin/showComment.jsp?page=<%=i %>&id=<%=id %>" class="num" ><%=i %></a>
									<%
								}
								%>...<%
							}else if(nowPage+size>=PageCount){
								for(int i=PageCount-showPages+1;i<=PageCount;i++){
									%>
									
									<a href="pages/comment/admin/showComment.jsp?page=<%=i %>&id=<%=id %>" class="num" ><%=i %></a>
									<%
								}
							}
						}else if(PageCount<=showPages){
							for(int i=1;i<=PageCount;i++){
								%>
								<a href="pages/comment/admin/showComment.jsp?page=<%=i %>&id=<%=id %>" class="num" ><%=i %></a>
								<%
							}
						}
						
						if(nowPage<PageCount){
							%>
							<a href="pages/comment/admin/showComment.jsp?page=<%=nowPage+1 %>&id=<%=id %>" class="page" ">下一页</a>
							<%
						}
						%>
						<li>共<%= cc.getCount(id)%>页&emsp;</li>
						 <form name="form_test"  style="display:inline;" action="pages/comment/admin/showComment.jsp" method="post" >
						 <input type="submit" value="跳到">
							  <input  type="text" style="width:30px; border:1px solid #CCC;" name="page" value="<%=nowPage %>"/>&emsp;页
							  <input type="hidden" name="id" value="<%=id %>">
                             </form>
					</ul>
		</div>
  </body>
</html>
